<include file="public@meta" />
<body>
<div class="layui-card">
    <div class="layui-card-body">
        <form method="post" action="{:url('setRules')}" class="layui-form">
            <input type="hidden" name="id" value="{$info.id}">
            <div class="layui-form-item">
                <table class="layui-table">
                    <colgroup>
                        <col width="80">
                        <col width="200">
                        <col>
                    </colgroup>
                    <thead>
                    <tr>
                        <th>选择</th>
                        <th>名称</th>
                        <th>URL</th>
                    </tr>
                    </thead>
                    <tbody id="tbody">
                    <volist name="$rules" id="v">
                        <tr>
                            <td><input type="checkbox" lay-filter="rules" data-pid="{$v.pid}" name="rules[]" value="{$v['id']}" <if condition="in_array($v['id'], $info['res'])"> checked</if> >
                            </td>
                            <td>{$v['title']}</td>
                            <td>{$v['name']}</td>
                        </tr>
                    </volist>
                    </tbody>
                </table>
            </div>

            <div class="layui-form-item layui-hide">
                <input type="button" lay-submit lay-filter="layui-btn-form-submit" id="layui-btn-form-submit" value="确认添加">
                <input type="button" lay-submit lay-filter="layui-btn-form-edit" id="layui-btn-form-edit" value="确认编辑">
            </div>
        </form>
    </div>
</div>
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        layCenter: 'lib/layCenter', //主入口模块
    }).use(['index', 'form','layCenter','common'], function(){
        var $ = layui.$,
            form = layui.form,
            layCenter = layui.layCenter,
            common = layui.common;
        form.on('checkbox(rules)', function (data) {
            var pid = data.value;
            if (data.elem.checked) {
                $("input[type=checkbox]").each(function (i) {
                    var text = $(this).data('pid');
                    if (text == pid) {
                        $(this).prop("checked", true);
                        form.render('checkbox');
                    }
                });
            } else {
                $("input[type=checkbox]").each(function (i) {
                    var text = $(this).data('pid');
                    if (text == pid) {
                        $(this).prop("checked", false);
                        form.render('checkbox');
                    }
                });
            }
        });
        //监听提交
        form.on('submit(layui-btn-form-submit)', function(data){
            layCenter.FormSubmit("{:url('setRules')}",data.field,true);
        });

    });
</script>
</body>
